{{ .datagrid }}

<!-- 权限设置 -->
<div id="admin_rolelist_permission_dialog" class="easyui-dialog" title="权限设置"
     data-options="modal:true,closed:true,iconCls:'icons-lock-lock_edit',buttons:[{text:'确定',iconCls:'icons-other-tick',handler:function(){$('#admin_rolelist_permission_dialog_form').submit();}},{text:'取消',iconCls:'icons-arrow-cross',handler:function(){$('#admin_rolelist_permission_dialog').dialog('close');}}]"
     style="width:500px;height:700px;"></div>

<!-- 添加角色 -->
<div id="admin_rolelist_add_dialog" class="easyui-dialog" title="添加角色"
     data-options="modal:true,closed:true,iconCls:'icons-application-application_add',buttons:[{text:'确定',iconCls:'icons-other-tick',handler:function(){$('#admin_rolelist_add_dialog_form').submit();}},{text:'取消',iconCls:'icons-arrow-cross',handler:function(){$('#admin_rolelist_add_dialog').dialog('close');}}]"
     style="width:480px;height:300px;"></div>

<!-- 编辑角色 -->
<div id="admin_rolelist_edit_dialog" class="easyui-dialog" title="编辑角色"
     data-options="modal:true,closed:true,iconCls:'icons-application-application_edit',buttons:[{text:'确定',iconCls:'icons-other-tick',handler:function(){$('#admin_rolelist_edit_dialog_form').submit();}},{text:'取消',iconCls:'icons-arrow-cross',handler:function(){$('#admin_rolelist_edit_dialog').dialog('close');}}]"
     style="width:480px;height:300px;"></div>

<script type="text/javascript">
    var admin_rolelist_datagrid_toolbar = [
        {text: '添加角色', iconCls: 'icons-arrow-add', handler: adminRoleListAdd},
        {text: '刷新', iconCls: 'icons-arrow-arrow_refresh', handler: adminRoleListRefresh}
    ];
    //状态格式化
    function adminRoleListStateFormatter(val) {
        return val === 1 ? '<font color="red">未启用</font>' : '已启用';
    }
    //操作格式化
    function adminRoleListOperateFormatter(val) {
        var btn = ["<div class=\"btn-group-sm\">"];

        if (val !== 1) {
            // btn.push('权限设置');
            // btn.push('编辑');
            // btn.push('删除');
        // } else {
            btn.push('<a class="btn-info btn" href="javascript:void(0);" onclick="adminRoleListPermission(' + val + ')">权限设置</a>');
            btn.push('<a class="btn btn-default" href="javascript:void(0);" onclick="adminRoleListEdit(' + val + ')">编辑</a>');
            btn.push('<a class="btn btn-danger" href="javascript:void(0);" onclick="adminRoleListDelete(' + val + ')">删除</a>');
        }
        btn.push("</div>")
        return btn.join('');
    }
    //刷新
    function adminRoleListRefresh() {
        $('#admin_rolelist_list_datagrid').datagrid('reload');
    }
    //添加
    function adminRoleListAdd() {
        $('#admin_rolelist_add_dialog').dialog({href: '/b/admin/role-add'});
        $('#admin_rolelist_add_dialog').dialog('open');
    }
    //编辑
    function adminRoleListEdit(id) {
        if (typeof(id) !== 'number') {
            $.messager.alert('提示信息', '未选择角色', 'error');
            return false;
        }
        var url = '/b/admin/role-edit';
        url += url.indexOf('?') != -1 ? '&id=' + id : '?id=' + id;
        $('#admin_rolelist_edit_dialog').dialog({href: url});
        $('#admin_rolelist_edit_dialog').dialog('open');
    }
    //删除
    function adminRoleListDelete(id) {
        if (typeof(id) !== 'number') {
            $.messager.alert('提示信息', '未选择角色', 'error');
            return false;
        }
        $.messager.confirm('提示信息', '确定要删除吗？', function (result) {
            if (!result) return false;
            $.post('/b/admin/role-delete', {id: id}, function (res) {
                if (res.errcode) {
                    $.messager.alert('提示信息', res.errmsg, 'error');
                } else {
                    $.messager.alert('提示信息', res.errmsg, 'info');
                    adminRoleListRefresh();
                }
            }, 'json');
        });
    }
    //角色权限
    function adminRoleListPermission(id) {
        if (typeof(id) !== 'number') {
            $.messager.alert('提示信息', '未选择角色', 'error');
            return false;
        }
        var url = '/b/admin/role-permission';
        url += url.indexOf('?') != -1 ? '&id=' + id : '?id=' + id;
        $('#admin_rolelist_permission_dialog').dialog({href: url});
        $('#admin_rolelist_permission_dialog').dialog('open');
    }
</script>